package com.love_weinuo.ui.activity;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;

import com.lzy.okgo.callback.StringCallback;
import com.love_weinuo.R;
import com.love_weinuo.databinding.ActivityMyideaBinding;
import com.love_weinuo.ui.BaseActivity;
import com.love_weinuo.util.HTTPAPI;
import com.love_weinuo.util.LogUtil;
import com.love_weinuo.util.SpUtils;
import com.love_weinuo.util.ToastUtil;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by SensYang on 2019/03/01 12:47
 */

public class MyIdeaActivity extends BaseActivity {

    ActivityMyideaBinding binding;
    String userId = (String) SpUtils.get("module_user_id", "");

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_myidea);
        binding.setActivity(this);
        initView();
    }

    private void initView() {
        add(this);
        setBack();
        setTitleText("意见反馈");

        binding.tvModuleUpata.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tvModuleUpata:
                updataSuggest();
                break;
            default:
        }
    }

    public void updataSuggest() {
        String suggest = binding.search.getText().toString().trim();
        if (TextUtils.isEmpty(suggest)) {
            showInCommonDialog("请输入您的建议");
            return;
        }
        HTTPAPI.getInstance().updataSuggest(userId, suggest, new StringCallback() {
            @Override
            public void onSuccess(String s, Call call, Response response) {
                LogUtil.e("提交反馈意见成功" + s);
                binding.search.setText("");
                ToastUtil.showToast("提交成功，谢谢您的宝贵意见");
                finish();
            }

            @Override
            public void onError(Call call, Response response, Exception e) {
                LogUtil.e("提交反馈意见失败" + e.getMessage());
            }
        });
    }

}
